<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Silence
 * Date: 3/8/12
 * Time: 3:50 AM
 * To change this template use File | Settings | File Templates.
 */

require_once('constants.php');
require_once('api.php');

$con = db_prepare();

$sql = "DROP TABLE IF EXISTS `sources`";
db_die(mysql_query($sql));
$sql = "CREATE TABLE IF NOT EXISTS `sources` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'item id',
  `name` varchar(255) DEFAULT '' COMMENT 'source name',
  `description` varchar(255) DEFAULT '' COMMENT 'item description',
  `cost` double DEFAULT 0.00 COMMENT 'actual cost of item',
  `pid` bigint(20) DEFAULT -1 COMMENT 'parent of source = an item id',
  PRIMARY KEY (`id`)
)";

db_die(mysql_query($sql));

$data = array();
$data[] = array(1, 'Raffles Hall', 'Raffles Hall', 1000, 22);
$data[] = array(2, 'KE VII Hall', 'KEVII Hall', 2000, 22);
$data[] = array(3, 'Tembusu College', 'UTown', 2500, 22);
$data[] = array(4, 'PGP BBQ-Pit', '@PGP', 20, 21);
$data[] = array(5, 'YiH BBQ-Pit', '@YiH', 50, 21);

foreach ($data as $val) {
    $id = $val[0];
    $name = "'" . $val[1] . "'";
	$description = "'" . $val[2] . "'";
	$cost = $val[3];
	$pid = $val[4];
    $sql = "INSERT INTO `sources` (`id`, `name`, `description`, `cost`, `pid`) VALUES
			($id, $name, $description, $cost, $pid)";
    print $sql;
    db_die(mysql_query($sql));
}

mysql_close($con);